package net.onceface.web.utils;

import net.onceface.infra.util.Assert;

import org.apache.shiro.crypto.hash.Md5Hash;

public class MD5EncryptService implements EncryptService {
	private int hashIterations = 1;

    private boolean saltDisabled = false;

	@Override
	public String encryptPassword(String password, String salt) throws IllegalArgumentException {
		Assert.notBlank(password, "password cannot be empty.");
        if (saltDisabled) {
            salt = null;
        }
        return new Md5Hash(password, salt, hashIterations).toHex();
	}

	@Override
	public String getCredentialsStrategy() {
		return Md5Hash.ALGORITHM_NAME;
	}

	@Override
	public int getHashIterations() {
		return hashIterations;
	}

	@Override
	public boolean saltDisabled() {
		// TODO Auto-generated method stub
		return saltDisabled;
	}
	
	public void setSaltDisabled(boolean disabled) {
        this.saltDisabled = disabled;
    }

    public void setHashIterations(int hashIterations) {
        this.hashIterations = hashIterations;
    }

}
